package com.example.springblog.service;

import com.example.springblog.mapper.BlogMapper;
import com.example.springblog.mapper.UserInfoMapper;
import com.example.springblog.model.BlogInfo;
import com.example.springblog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * Date: 2024-08-26
 * Time: 17:53
 */
@Slf4j
@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogMapper blogMapper;

    @Autowired
    private BlogMapper blogInfoMapper;

    public UserInfo selectByName(String name) {
        return userInfoMapper.selectByName(name);
    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //根据博客 ID 获取作者 ID
        //根据作者 ID 获取作者信息
        //BlogInfo blogInfo = blogInfoMapper.
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if (blogInfo==null && blogInfo.getUserId()<=0){
            log.error("博客不存在或博客作者信息不合法, blogId:{}", blogId);
            return null;
        }

        return userInfoMapper.selectById(blogId);
    }
}
